package algo_lignes_sites.trt;

import algo_lignes_sites.data.Data_ls;
import commons.ihm.courbe.PanelCourbe;
import commons.logs.Logger;
import commons.utils.UtilsTime;
import commons.utils.primitive_geom.Point_d;
import java.awt.Color;

public class DialogDetailsTraitement extends javax.swing.JDialog {

	private PanelCourbe panelCourbeVitessePoints;
	private PanelCourbe panelCourbeNbIntersect;

	private int nbTotalIter;

	public DialogDetailsTraitement() {
		initComponents();
	}

	
	public void initDisplay(int nbTotalIter) {
		this.nbTotalIter = nbTotalIter;

		panelCourbeVitessePoints = new PanelCourbe();
		panelCourbeVitessePoints.addCourbe(Color.GREEN);
		panelCourbeVitessePoints.addCourbe(Color.ORANGE);
		panelCourbeVitessePoints.addCourbe(Color.RED);
		panelCourbeVitessePoints.setNbPointBetweenAutomaticRepaint(3);
		panelCourbeVitessePoints.configureDisplay(0, nbTotalIter, 0, 100);
		container_PanelCourbeVitessePoints.add(panelCourbeVitessePoints, java.awt.BorderLayout.CENTER);

		panelCourbeNbIntersect = new PanelCourbe();
		panelCourbeNbIntersect.addCourbe(Color.BLUE);
		panelCourbeNbIntersect.setNbPointBetweenAutomaticRepaint(1);
		panelCourbeNbIntersect.configureDisplay(0, nbTotalIter, 0, 30);
		container_PanelCourbeNBIntersect.add(panelCourbeNbIntersect, java.awt.BorderLayout.CENTER);
	}


	public void updateDisplay(int numIter, Data_ls data) {
		// Quelques statistiques
		if (numIter%5 == 0 || numIter>=nbTotalIter-5) {
			double[] vitesses = data.getVitessesRelatives();
			panelCourbeVitessePoints.addPoint(new Point_d(numIter, vitesses[0]*100), 0);
			panelCourbeVitessePoints.addPoint(new Point_d(numIter, vitesses[1]*100), 1);
			panelCourbeVitessePoints.addPoint(new Point_d(numIter, vitesses[2]*100), 2);
		}

		if (numIter%10 == 0 || numIter>=nbTotalIter-5) {
			UtilsTime.startTimer("calcul new intersections");
			int nbNewIntersect = data.getNbNewIntersect_DER();
			double nbNewIntersectRelatif = (double)nbNewIntersect / data.getVPathDER().size();
			UtilsTime.stopTimer("calcul new intersections");
			Logger.log_DEBUG1("### " + UtilsTime.getStringDuree("calcul new intersections"));
			panelCourbeNbIntersect.addPoint(new Point_d(numIter, nbNewIntersectRelatif*100), 0);

			label_InfoNbItersect.setText(nbNewIntersect + " / nbPathTotal=" + data.getVPathDER().size());
		}
	}


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel4 = new javax.swing.JLabel();
        container_PanelCourbeNBIntersect = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        container_PanelCourbeVitessePoints = new javax.swing.JPanel();
        label_InfoNbItersect = new javax.swing.JLabel();

        setTitle("Détails du Traitement de la passe courante");
        setResizable(false);
        setUndecorated(true);

        jLabel4.setText("Qualité du traitement : nb de points d'intersection créés : ");

        container_PanelCourbeNBIntersect.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
        container_PanelCourbeNBIntersect.setLayout(new java.awt.BorderLayout());

        jLabel3.setText("Pour info : vitesse des points");

        container_PanelCourbeVitessePoints.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
        container_PanelCourbeVitessePoints.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(label_InfoNbItersect, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE))
                    .addComponent(jLabel3)
                    .addComponent(container_PanelCourbeVitessePoints, javax.swing.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE)
                    .addComponent(container_PanelCourbeNBIntersect, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(label_InfoNbItersect, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(container_PanelCourbeNBIntersect, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(container_PanelCourbeVitessePoints, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel container_PanelCourbeNBIntersect;
    private javax.swing.JPanel container_PanelCourbeVitessePoints;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel label_InfoNbItersect;
    // End of variables declaration//GEN-END:variables


}

